<?php

namespace app\store\model\server;

use app\common\model\server\Capital as CapitalModel;

/**
 * 分销商资金明细模型
 * Class Apply
 * @package app\store\model\dealer
 */
class Capital extends CapitalModel
{
    /**
     * 获取分销商提现列表
     * @param null $user_id
     * @param int $flow_type
     * @param string $search
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    public function getList($user_id = null, $flow_type = -1, $search = '')
    {
        // 构建查询规则
        $this->alias('capital')
            ->with(['user'])
            ->field('capital.*, server.real_name, server.mobile, user.nickName, user.avatarUrl')
            ->join('user', 'user.user_id = capital.user_id')
            ->join('server_user server', 'server.user_id = capital.user_id')
            ->order(['capital.create_time' => 'desc']);
        // 查询条件
        $user_id > 0 && $this->where('capital.user_id', '=', $user_id);
        !empty($search) && $this->where('server.real_name|server.mobile', 'like', "%$search%");
        $flow_type > 0 && $this->where('capital.flow_type', '=', $flow_type);
        // 获取列表数据
        return $this->paginate(15, false, [
            'query' => \request()->request()
        ]);
    }

    /**
     * 获取器：打款方式
     * @param $value
     * @return mixed
     */
    public function getFlowTypeAttr($value)
    {
        $status_arr = [10 => '服务收入', 20 => '工资发放'];
        return ['text' => $status_arr[$value], 'value' => $value];
    }
}